<?php

namespace app\admin\controller\xuboss;

use app\common\controller\Backend;
use think\Session;

class Carousel extends Backend
{
    public function _initialize()
    {
        parent::_initialize();
        $this->model = model('xuboss.carousel');
        $this->service_secret = Session::get('admin')['secret'];
        if (empty($this->service_secret))
            $this->service_secret = "Jp)GuX=M^KthZV7^";
        if (!empty(Session::get('admin')['secret'])) {
            $this->model
                ->where(['service_secret' => $this->service_secret]);
        }
    }
    public function index()
    {
        //设置过滤方法
        $this->request->filter(['strip_tags', 'trim']);
        if ($this->request->isAjax()) {
            //如果发送的来源是Selectpage，则转发到Selectpage
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();
            $list = $this->model
                ->with(['menu'])
                ->where($where)
                ->where(['carousel.service_secret'=>$this->service_secret])
                ->order($sort, $order)
                ->paginate($limit);
            $result = array("total" => $list->total(), "rows" => $list->items());
            return json($result);
        }
        return $this->view->fetch();
    }
}